<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@ taglib uri="http://myfaces.apache.org/tomahawk" prefix="t"%>

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<f:view>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Java Programming</title>
<link href="http://www.uark.edu/rd_vcad/inc/jQuery/prettify/prettify.css" type="text/css" rel="stylesheet" /> 
<script type="text/javascript" src="http://www.uark.edu/rd_vcad/inc/jQuery/prettify/prettify.js"></script>
</head>
<script type="text/javascript">
	function findKeyWords(){
		var content = document.getElementById("myJavaForm:codeTextArea").value;
		alert(content);
		var splitArr = content.split(" ");
		var keyWords ="abstract continue for new switch assert	default	goto package synchronized boolean do if	private	this break double implements protected throw byte else import public throws case enum instanceof return transient catch extends int short try char final interface static void class finally long strictfp volatile const float native super while"
		var keyWordsArr = keyWords.split(" ");
		//alert("class length "+splitArr.length);
		//alert("keyWords length "+keyWordsArr.length);
		for(i=0;i<splitArr.length;i++){
			// alert(splitArr[i]);
			//for(j=0;j<keyWordsArr.length;j++){
				//if(splitArr[i]==keyWordsArr[j]){
					// alert("matched:"+splitArr[i]);
					document.getElementById("myJavaForm:codeTextArea").value="<b>"+content+"</b>";
				//}
			//}
		}
		
	}
	function getSelectedClass(){
		var selClass = document.getElementById("myJavaForm:mysele").value;
		alert("selClass:"+selClass);
	}
	function getSelClass(rowIndex){
		//alert(rowIndex);
		//alert(document.getElementById('myJavaForm:dataTableId:'+rowIndex+':classNameId').innerHTML);
		document.getElementById('myJavaForm:hiddenFullPath').value = document.getElementById('myJavaForm:dataTableId:'+rowIndex+':classNameId').innerHTML;
	}
	function getSelJarToDelete(rowIndex){
		//alert(rowIndex);
		//alert(document.getElementById('myJavaForm:dataTableId:'+rowIndex+':classNameId').innerHTML);
		document.getElementById('myJavaForm:hiddenJarFullPath').value = document.getElementById('myJavaForm:jarDataTableId:'+rowIndex+':jarNameId').innerHTML;
		//alert(document.getElementById('myJavaForm:hiddenJarFullPath').value);
	}
</script>
<body>
	<h:form id="myJavaForm">
	<div style="width: 100%; overflow: hidden;">
		<div style="height: 630px; width: 300px; border: groove;border-color: red; overflow: auto;float: left;" >
			<h:panelGrid columns="1" cellpadding="2" cellspacing="2" border="3" style="width: 300px; height: 630px; vertical-align: top;color: black; background: lightgray;">
						<h:panelGroup style="height: 10px;color: black; background: lightgray;">
							<h:outputText style="white-space:nowrap;font-weight:bold" value="Current User"/>
							<h:outputText value=" "/>
							<h:outputText id="srcId" value="#{userDetailsBean.gmailId}"/>
						</h:panelGroup>
						<h:panelGroup style="height: 10px;color: black; background: lightgray;">
							<h:commandLink action="" value="logout"/>
						</h:panelGroup>
						<h:panelGroup style="height: 10px;color: black; background: lightgray;">
							<h:outputLabel value="Browse your files"/>
						</h:panelGroup>
						<h:panelGroup style="height: 400px;color: black; background: lightgray;">
							<t:dataTable styleClass="ruler" var="classNameVar" rowIndexVar="currentRow" id="dataTableId" style="text-align=center;width: 250px"
									value="#{javaManagedBean.listOfFiles}" rows="15" cellpadding="0" cellspacing="0" >
								<h:column>
	      							<f:facet name="header"><h:outputText style="white-space:nowrap" value="Java File"/></f:facet>
	      							<h:outputText id="classNameId" style="align:left" value="#{classNameVar.className}"/>
	      						</h:column>
	    						<h:column>
	    							<h1>  </h1>
	    						</h:column>
	    						<h:column>
	      							<f:facet name="header"><h:outputText style="white-space:nowrap" value="Open"/></f:facet>
	      							<h:commandButton value="Open" id="openAction" action="#{javaManagedBean.openAction}" onclick="getSelClass('#{currentRow}')"  title="click to open file"/>
	      						</h:column>
	      						<h:column>
	    							<h1>  </h1>
	    						</h:column>
	      						<h:column>	
	      						    <f:facet name="header"><h:outputText style="white-space:nowrap" value="Delete"/></f:facet>
	      							<h:commandButton value="Delete" id="deleteAction" action="#{javaManagedBean.deleteAction}" onclick="getSelClass('#{currentRow}')" title="click to Delete file"/>
	    						</h:column>	
							</t:dataTable>
								<t:dataScroller id="dataScrollerId" for="dataTableId" fastStep="10"
							        pageIndexVar="pageIndex" renderFacetsIfSinglePage="true"
							        pageCountVar="pageCount" paginator="true" paginatorMaxPages="9"
							        immediate="true">
							        <f:facet name="first">
							            <t:outputText value="First"></t:outputText>
							        </f:facet>
							        <f:facet name="last">
							            <t:outputText value="Last"></t:outputText>
							        </f:facet>
							        <f:facet name="previous">
							            <t:outputText value="Previous"></t:outputText>
							        </f:facet>
							        <f:facet name="next">
							            <t:outputText value="Next"></t:outputText>
							        </f:facet>
							  </t:dataScroller>    
					    <h:inputHidden id="hiddenFullPath" value="#{javaManagedBean.selClassName}"></h:inputHidden>
					    <h:inputHidden id="gmailId" value="#{javaManagedBean.gmailId}"></h:inputHidden>
						</h:panelGroup>
			</h:panelGrid>
		</div>
		<div style="height: 630px;width: 640px;border: groove;border-color: red; overflow: auto;float: left;">
			<h:panelGrid columns="1" cellspacing="3" cellpadding="3" border="3" title="Java Online IDE" style="height: 600px; width: 630px; color: black; background: lightgray;">
				
					<h:panelGroup>
						<f:facet name="header">
							<h:outputText value="Java Online IDE" style="align :center;" />
						</f:facet>
					</h:panelGroup>
					<h:panelGroup>
						<h:outputLabel value="Save or Run your java programs Here" style="align: center;"/>
					</h:panelGroup>
					<h:panelGroup>
						<h:outputLabel value="Enter class Name" style="align: center;"/>
						<h:inputText id="classNameId" value="#{javaManagedBean.className}"/>
					</h:panelGroup>	
					<h:panelGroup>
						<h:outputLabel value="Enter class Content" style="align: center;"/>
						<h:commandButton id="onlySaveIdfirst" action="#{javaManagedBean.saveProgram}" value="Only Save" style="align: center; color: black; background: lightgray;" />
						<h:commandButton id="runfirst" action="#{javaManagedBean.runProgram}" value="Save && Run" style="align: center; color: black; background: lightgray;" />
						<h:commandButton id="clearIdfirst" action="#{javaManagedBean.clear}" value="Clear" style="align: center; color: black; background: lightgray;"/>
					</h:panelGroup>		
					<h:panelGroup>
						<t:inputTextarea id="codeTextArea" value="#{javaManagedBean.codeText}" style="width: 600px; height: 486px" wrap="off"/>
					</h:panelGroup>
					<h:panelGroup>
					    <h:commandButton id="onlySaveId" action="#{javaManagedBean.saveProgram}" value="Only Save" style="align: center; color: black; background: lightgray;" />
						<h:commandButton id="run" action="#{javaManagedBean.runProgram}" value="Save && Run" style="align: center; color: black; background: lightgray;" />
						<h:commandButton id="clearId" action="#{javaManagedBean.clear}" value="Clear" style="align: center; color: black; background: lightgray;"/>
					</h:panelGroup>
					<h:panelGroup>
						<h:outputLabel value="Console" style="align: center; color: black; background: lightgray;"/>
					</h:panelGroup>
					<h:panelGroup>
						<t:inputTextarea id="consoleTextArea" value="#{javaManagedBean.output}" style="width: 600px; height: 126px" wrap="off"/>
					</h:panelGroup>
					
			</h:panelGrid>
		</div>
		
		<div style="height: 630px;width: 280px;border:groove;border-color: red; overflow: auto;">
			<h:panelGrid columns="1" cellspacing="3" cellpadding="3" border="3" style="height: 600px; width: 280px; color: black; background: lightgray; vertical-align: top">
					<h:panelGroup style="height: 10px;">
						<h:outputLabel value="Add Required jar files"/>
					</h:panelGroup>
					<h:panelGroup style="height: 250px;">
						<h:selectManyMenu id="selectJarId" value="#{javaManagedBean.selectedJarList}" style="height: 137px; ">
						  	<f:selectItems value="#{javaManagedBean.listOfJarFiles}"/>
						</h:selectManyMenu>
					</h:panelGroup>
					<h:panelGroup style="height: 10px;">
						<h:outputLabel value="Available Jars in Classpath" style="align: center;"/>
					</h:panelGroup>
					<h:panelGroup style="height: 10px;">
						<h:outputLabel value="Jar Name" style="align: left;"/>
						<h:outputLabel value="     " style="align: center;"/>
						<h:outputLabel value="Delete" style="align: right;"/>
					</h:panelGroup>
					<h:panelGroup style="height: 250px;color: black; background: white;">
						<t:dataTable styleClass="ruler" var="jarNameVar" rowIndexVar="currentJarRow" id="jarDataTableId" style="text-align=center;height: 215px"
								value="#{javaManagedBean.availableJarList}" rows="15" cellpadding="0" cellspacing="0" >
							<h:column >
      							<h:outputText id="jarNameId" style="align:left" value="#{jarNameVar.jarName}"/>
      						</h:column>
    						<h:column>	
      							<h:commandButton value="Delete" id="deleteJar" action="#{javaManagedBean.deleteJar}" onclick="getSelJarToDelete('#{currentJarRow}')" title="click to Delete file"/>
    						</h:column>
    					</t:dataTable>
					</h:panelGroup>
					<h:inputHidden id="hiddenJarFullPath" value="#{javaManagedBean.selJarToDel}"></h:inputHidden>
				
			</h:panelGrid>
		</div>
	</div>	
				
	</h:form>

</body>
</html>
</f:view>